package arg

import (
	"db2s/global"
	"reflect"
	"strings"
)

type slowLevel struct {
}

// slowLevelParameter parameter check
func (rc *ConfigParameter) slowLevelParameter() error {
	var (
		slowParMap = make(map[string]any)
		err        error
		s2         = make(map[string]any)
		f3         = rc.FirstL1.Inspection.ToConfig().GetObject("slowLog").ToConfig()
	)
	rc.SecondaryL.FunctionalMode = "slowLog"
	if slowParMap, err = global.StructSubToMapAny(SlowLog{}); err != nil {
		return err
	}
	for k, v := range slowParMap {
		if r1 := rc.getHoconConfigVal1(f3, k, reflect.TypeOf(v).String()); r1 != nil {
			s2[k] = r1
		} else {
			s2[k] = v
		}
	}
	if err = global.MapSubToStructSubJsonName(s2, &rc.SecondaryL.InspectionV.SlowLogV); err != nil {
		return err
	}
	start := rc.SecondaryL.InspectionV.SlowLogV.InputV.FilterV.TimeLimitV.StartTime
	end := rc.SecondaryL.InspectionV.SlowLogV.InputV.FilterV.TimeLimitV.EndTime
	rc.SecondaryL.InspectionV.SlowLogV.InputV.FilterV.TimeLimitV.StartTime = strings.ReplaceAll(start, "\"", "")
	rc.SecondaryL.InspectionV.SlowLogV.InputV.FilterV.TimeLimitV.EndTime = strings.ReplaceAll(end, "\"", "")
	return nil
}
